using System;
using System.Globalization;
using System.Windows.Data;
using MediaAssistant.Data;
using MefBasic.Threading;
using MediaAssistant.DAL;

namespace MediaAssistant
{
    public class MovieIndexConverter:IMultiValueConverter
    {
        private static void InitializeMovieForList(Job obj)
        {
            var movie = obj.Store.GetObject<Movie>();
            var dataSource = obj.Store.GetObject<LibraryDataSource>();
            dataSource.InitializeMovieForList(movie);
        }

        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            var movie = values[0] as Movie;
            var dataSource = values[2] as LibraryDataSource;
            if (movie != null && dataSource!=null)
            {
                var job = new Job(InitializeMovieForList);
                job.Store.Add(movie);
                job.Store.Add(dataSource);
                job.Start();
            }
            return values[1];
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}